// pages/home/detailInfo/detailInfo.js
var serveUrl = require('../../../utils/util.js').serveUrl
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recruitData:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log("uuuuu")
    console.log(options)
    // that.setData({
    //   mername: options.mername//options为页面路由过程中传递的参数
    // })
  
    // 根据招聘id获取招聘详情
    that.getRecruitDetail(options.recruitId);
    // 增加阅读次数
    that.addLookTimes(options.recruitId)
  },
// 有意此职位
  wantTheJobs(){
    var that=this;
    var datas=[];
    var obj={};
    obj.title ='填写个人信息';
    obj.recruitId = that.data.recruitData.recruit_id;
    datas.push(obj)
    wx.navigateTo({
      url: "../myInfos/myInfos?canshu="+JSON.stringify(datas),
      success: function (res) {
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  // 分享职位
  shareJobs(){
    var _this = this
    _this.setData({
      showst: false
    })
    wx.canvasToTempFilePath({ //生成图片
      x: 0,
      y: 0,
      width: 200,
      height: 310,
      destWidth: 189,
      destHeight: 310,
      quality: 1,
      canvasId: 'myCanvas',
      success: function (res) {
        wx.saveImageToPhotosAlbum({ //保存生成的图片到手机相册里
          filePath: res.tempFilePath,
          success(res) {
            console.log("res")
            // app.showToasts('保存成功')
            // _this.setData({
            //   showst: true
            // })
          }
        })
      }
    })
    wx.navigateTo({
      url: "../jobShare/jobShare",
      success: function (res) {
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  // 增加阅读次数
  addLookTimes(recruitId){
    wx.request({
      url: serveUrl + "add_view_counts",
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      method: "POST",
      data: {
        recruit_id: recruitId
      },
      success: function (res) {
        console.log("增加浏览次数")
        // wx.hideToast();
        console.log(res);
      }
    })
  },
  // 招聘详情数据
  getRecruitDetail(recruitId){
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 3000
    });
    var that=this;
    console.log(recruitId)
     wx.request({
       url: serveUrl +"get_recruit_data_by_recruit_id_from_phone",
        header: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
        method: "POST",
        data:{
          recruit_id: recruitId
        },
        success: function(res) {
          console.log("pppppppp")
          wx.hideToast();

          console.log(res);
            that.setData({
              recruitData: res.data.data[0]
            });
            wx.setNavigationBarTitle({
              title: res.data.data[0].job_position//页面标题为路由参数
            });
        }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})